import os
import sys
import os.path

rootdir = "/home/letitia/py-R-FCN/data/VOCdevkit0712/VOC0712/JPEGImages"
#rootdir = "/home/letitia/py-R-FCN/data/VOCdevkit2007/task_10216/JPEGImages"

for path,subdir,dirnames in os.walk(rootdir):
	for dirname in dirnames:
		s = dirname.split('.')
		if s[1] == "JPG":
			oldfile = os.path.join(path, dirname)
			newfile = os.path.join(path, s[0] + '.jpg')
			os.rename(oldfile, newfile)
			#print oldfile + 'changed to  ' + newfile